<template>
	<view :class="['page',{'iphoneX':isIphoneX}]">
		<view class="body"> 
			
			<view class="tools-list">
				<view v-if="userInfo.role_id!=24" data-url="/package_project/index/index" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/xiangmu_icon.png" mode="widthFix"></image></view>
					<view class="name">项目管理</view>
				</view>
				<!-- <view data-url="/" data-isopen="0" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/rs_icon.png" mode="widthFix"></image></view>
					<view class="name">人事管理</view>
				</view> -->
				<!-- <view data-url="/" data-isopen="0" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/cw_icon.png" mode="widthFix"></image></view>
					<view class="name">财务管理</view>
				</view> -->
				<!-- <view data-url="/" data-isopen="0" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/kehu_icon.png" mode="widthFix"></image></view>
					<view class="name">客户管理</view>
				</view> -->
				<view v-if="userInfo.role_id!=24" data-openType="navagite" data-url="/package_caigou/list/list" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/cg_icon.png" mode="widthFix"></image></view>
					<view class="name">采购管理</view>
				</view>
				<view data-url="/package_kucun/list/list" data-isopen="1" data-openType="navagite" data-iskucun="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/cc_icon.png" mode="widthFix"></image></view>
					<view class="name">库存管理</view>
				</view>
				<view data-url="/package_shengchan/list/list?type=add" data-openType="navagite" data-isopen="1" data-iskucun="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/shengchan_icon.png" mode="widthFix"></image></view>
					<view class="name">生产需求</view>
				</view>
				<!-- <view v-if="userInfo.role_id==48||userInfo.role_id==31||userInfo.role_id==29||userInfo.role_id==1" data-url="/package_tools/index/index" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/sb_xq.png" mode="widthFix"></image></view>
					<view class="name">小工具</view>
				</view> -->
				<navigator url="/pages/shouce/shouce" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/shouce_icon.png" mode="widthFix"></image></view>
					<view class="name">员工手册</view>
				</navigator>
				<view v-if="userInfo.role_id==1||userInfo.id==55" data-url="/package_keyan/list/list" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/keyan_icon.png" mode="widthFix"></image></view>
					<view class="name">科研项目</view>
				</view>
				<view data-url="/package_shengchan/chuchang/chuchang" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/chuchang_icon.png" mode="widthFix"></image></view>
					<view class="name">出厂审批</view>
				</view>
				<navigator url="/package_kehu/list/list" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/kehu_icon.png" mode="widthFix"></image></view>
					<view class="name">客户管理</view>
				</navigator>
				<navigator url="/package_gongyingshang/list/list" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/gongyinshang_icon.png" mode="widthFix"></image></view>
					<view class="name">供应商管理</view>
				</navigator>
				<view data-url="/package_shebeixuqiu/list/list" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/shengchan_icon.png" mode="widthFix"></image></view>
					<view class="name">生产任务</view>
				</view>
				<view data-url="/package_tools/baocan/baocan?page=1" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/baocan_icon.png" mode="widthFix"></image></view>
					<view class="name">报餐</view>
				</view>
				<!-- <view data-url="/package_tools/guzhangchuli/guzhangchuli" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/toubiao_icon.png" mode="widthFix"></image></view>
					<view class="name">故障处理</view>
				</view>
				<view data-url="/package_tools/shangbaoguzhang/shangbaoguzhang" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/toubiao_icon.png" mode="widthFix"></image></view>
					<view class="name">上报故障</view>
				</view>
				<view data-url="/package_tools/zhipaiguzhang/zhipaiguzhang" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/toubiao_icon.png" mode="widthFix"></image></view>
					<view class="name">指派故障</view>
				</view>
				<view data-url="/package_tools/shenhegongdan/shenhegongdan" data-openType="navagite" data-isopen="1" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/toubiao_icon.png" mode="widthFix"></image></view>
					<view class="name">审核工单</view>
				</view> -->
				<!-- <view data-url="/" data-isopen="0" class="item" @click="jump">
					<view class="icon"><image src="@/static/images/zhichan_icon.png" mode="widthFix"></image></view>
					<view class="name">知识产权管理</view>
				</view> --> 
			</view>
		
			<!-- <u-button type="primary" text="退出" @click="logout"></u-button> -->
		</view>
		
		<c-nav-index :switchTab="1"></c-nav-index> 
	</view>
</template>

<script> 
	import WebSocket from '@/common/websocket.js'
	export default {
		data() {
			return {
				isLogin:false,
				userInfo:uni.getStorageSync('userInfo'),
				isIphoneX:getApp().globalData.isIphoneX,
				systemInfo:uni.getSystemInfoSync(),
				loadingState:{
					default:true,
					loading:false,
					complete:false
				} 
			}
		},
		async onLoad() {
			this.isLogin=await this.$loginState('check');  
			console.log(this.userInfo)
			if(this.isLogin){
				 
				 
			}
		},
		async onShow() { 
			this.getUserInfo();
			
		},
		methods: { 
			
			 
			async getUserInfo(){ 			
				let res=await this.$api.user_api.Index();  
				console.log(res)
				if(res.data.code==200){
					if(res.data.data.isnew==1){
						uni.showModal({
							content:"新员工请先阅读员工手册，并完成签名确认",
							showCancel:false,
							confirmText:'去阅读',
							success(m_res) {
								if(m_res.confirm){
									uni.navigateTo({
										url:'/pages/shouce/shouce?type=1'
									})
								}
							}
						})
					} 
				}
			},
			
			// 退出登录
			logout:async function(){
				let _this=this;
				uni.showModal({
					content:"确定退出登录吗？",
					async success(res) {
						if(res.confirm){ 
							let logout_res=await _this.$api.user_api.logout(); 
							if(logout_res.data.code==200){
								uni.removeStorageSync('token');
								uni.removeStorageSync('userInfo');  
								WebSocket.close();
								uni.reLaunch({
									url:'/pages/login/login'
								})
							} 							
						}
					}
				})
				 
			},
			jump(e){ 
				
				let url=e.currentTarget.dataset.url,
				    isOpen=e.currentTarget.dataset.isopen, 
					openType=e.currentTarget.dataset.openType;
				// if(this.userInfo.role_id==24&&iskucun==0){
				// 	uni.showToast({
				// 		icon:'error',
				// 		title:'无权限访问',
				// 		mask:true
				// 	})
				// 	return 
				// }
				
				if(isOpen==0){
					uni.showToast({
						icon:'loading',
						title:'此功能暂未开放',
						mask:true
					})
					return 
				}
				if(openType=='navagite'){
					uni.navigateTo({
						url:url
					})
				}else{
					uni.reLaunch({
						url:url
					})
				}
				
			},
			 
		},
		
		computed:{ 
			 
		},
		watch:{
			 
		}
	}
</script>

<style lang="scss" scoped>
	.body{
		overflow: auto;
	}
	.tools-list{
		display: flex;
		flex-wrap: wrap;
		margin: 20rpx;
		padding: 20rpx;
		background: #fff;
		border-radius: 15rpx;
		.item{
			width: 24.5%;
			text-align: center;
			margin-bottom: 20rpx;
			.icon{
				width: 90rpx;
				margin: 0 auto 20rpx;
				image{
					width: 100%;
				}
			}
			.name{
				font-size: 28rpx;
			}
		}
	}
	 
</style>
